﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GatewayInspect.Common;

namespace GatewayInspect.Modules
{
    public partial class MGCY_NotPassedForm : Form
    {
        public string Problems
        {
            get
            {
                return this.tbxProblems.Text;
            }
        }

        public string Measures
        {
            get
            {
                return this.tbxMeasures.Text;
            }
        }

        public bool AddToBlackList
        {
            get
            {
                return this.chbBlacklist.Checked;
            }
        }

        public bool NeedToDate
        {
            get
            {
                return this.dtpYXQ.Checked;
            }
        }

        public DateTime ToDate
        {
            get
            {
                return this.dtpYXQ.Value.Date;
            }
        }

        private string _truckNo = string.Empty, _driverID = string.Empty;

        public MGCY_NotPassedForm(string truckno, string driverid)
        {
            InitializeComponent();
            this._truckNo = truckno;
            this._driverID = driverid;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.chbBlacklist.Checked && CheckBlacklistExit())
            {
                MessageBox.Show("该车辆信息已加入黑名单，不能重复加入！");
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private bool CheckBlacklistExit()
        {
            string strSQL = "select * from T_TRUCK_BLACKLIST where ISDEL = '0'";
            if (!string.IsNullOrWhiteSpace(_truckNo))
            {
                strSQL += " and TRUCKNO = '" + _truckNo + "'";
            }
            else
            {
                strSQL += " and TRUCKNO is null";
            }
            if (!string.IsNullOrWhiteSpace(_driverID))
            {
                strSQL += " and DRIVERID = '" + _driverID + "'";
            }
            else
            {
                strSQL += " and DRIVERID is null";
            }
            DataTable dtBlacklist = DataAccess.ExecuteDataTable(strSQL);
            if (dtBlacklist != null && dtBlacklist.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
    }
}
